package com.cmcc.groupcontacts.util;

import android.app.Activity;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;

/**
 * Activity辅助类
 * 
 * @author 
 * 
 */
public class ActivityHelper {
	private Activity activity;
	private Display display;
	private LayoutInflater inflater = null; // UI加载器

	public ActivityHelper(Activity activity) {
		this.activity = activity;
	}
	
	/**
	 * 获取屏显对象
	 * 
	 * @return
	 */
	public Display getDisplay() {
		if (display == null) {
			display = getDisplay(activity);
		}
		return display;
	}

	/**
	 * 获取布局加载器
	 * 
	 * @return
	 */
	public LayoutInflater getInflater() {
		if (inflater == null) {
			inflater = getInflater(activity);
		}
		return inflater;
	}
	
	// ========== static methods ==========

	/**
	 * 获取屏显对象
	 * 
	 * @param activity
	 * @return
	 */
	public static Display getDisplay(Context context) {
		return getDisplay((Activity) context);
	}

	/**
	 * 获取屏显对象
	 * 
	 * @param activity
	 * @return
	 */
	public static Display getDisplay(Activity activity) {
		return activity.getWindowManager().getDefaultDisplay();
	}
	
	/**
	 * 获取布局加载器
	 * 
	 * @return
	 */
	public static LayoutInflater getInflater(Context context) {
		return getInflater((Activity) context);
	}
	
	/**
	 * 获取布局加载器
	 * 
	 * @return
	 */
	public static LayoutInflater getInflater(Activity activity) {
		return (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
}
